#ifndef COMPILER_H
#define COMPILER_H

/* Types used by compiler */
#define CTYPE_VOID      1
#define CTYPE_ANY       2
#define CTYPE_STRING    3

/* Scopes of identifier */
extern CoValue *g_scope_efun;
extern CoValue *g_scope_function;
extern CoValue *g_scope_global;
extern CoValue *g_scope_local;

void Compiler_Init(void);
void Compiler_Destruct(void);

CoValue *Compiler_CompileFile(CoValue *mod_name, int fd);

CoValue *Compiler_GetIdentifierScope(CoValue *name);

void Compiler_FreeAllLocals(void);
void Compiler_PopLocals(int num);
int Compiler_AddLocal(CoValue *name, int type);
AstNode *Compiler_UseLocal(CoValue *name);

void Compiler_PopGlobals(int num);
int Compiler_AddGlobal(CoValue *name, int type);
AstNode *Compiler_UseGlobal(CoValue *name);

int Compiler_AddStringConst(CoValue *vstr);

void Compiler_DeclareNewFunction(CoValue *name, int type, int num_arg);
void Compiler_CheckFunctionDeclaration(CoValue *name, int type, int num_arg);
void Compiler_DefineFunction(CoValue *name, AstNode *node);
AstNode *Compiler_CallEFun(CoValue *name, AstNode *node);
AstNode *Compiler_CallFunction(CoValue *name, AstNode *node);
void Compiler_SetAstTree(AstNode *node);

void Compiler_Error(char *s);

#endif
